<template>
  <div class="hero-list">
    <div class="hero-header">
      <h3>拾物英雄榜</h3>
      <div class="header-tabs">
        <el-radio-group v-model="timeFilter" size="small">
          <el-radio-button label="week">本周</el-radio-button>
          <el-radio-button label="month">本月</el-radio-button>
          <el-radio-button label="all">总榜</el-radio-button>
        </el-radio-group>
      </div>
    </div>
    
    <div class="hero-cards">
      <div class="top-heroes">
        <div 
          v-for="(hero, index) in topThreeHeroes" 
          :key="hero.id" 
          class="top-hero-card"
          :class="`rank-${index + 1}`"
        >
          <div class="rank-badge">{{ index + 1 }}</div>
          <el-avatar :size="index === 0 ? 80 : 70" :src="hero.avatar" />
          <div class="hero-name">{{ hero.name }}</div>
          <div class="hero-stats">
            <div class="stat-item">
              <div class="stat-value">{{ hero.returnedItems }}</div>
              <div class="stat-label">归还物品</div>
            </div>
            <div class="stat-item">
              <div class="stat-value">{{ hero.helpedUsers }}</div>
              <div class="stat-label">帮助用户</div>
            </div>
          </div>
          <div class="honor-tag">{{ hero.honorTitle }}</div>
        </div>
      </div>
      
      <el-table
        :data="otherHeroes"
        style="width: 100%"
        :show-header="false"
        class="hero-table"
      >
        <el-table-column width="60">
          <template #default="scope">
            <div class="rank-number">{{ scope.$index + 4 }}</div>
          </template>
        </el-table-column>
        
        <el-table-column width="60">
          <template #default="scope">
            <el-avatar :size="40" :src="scope.row.avatar" />
          </template>
        </el-table-column>
        
        <el-table-column prop="name">
          <template #default="scope">
            <div class="table-hero-info">
              <span class="hero-name">{{ scope.row.name }}</span>
              <el-tag size="small" effect="plain" type="success">{{ scope.row.honorTitle }}</el-tag>
            </div>
          </template>
        </el-table-column>
        
        <el-table-column width="90">
          <template #default="scope">
            <div class="table-hero-stats">
              <div class="stat-number">{{ scope.row.returnedItems }}</div>
              <div class="stat-label">归还物品</div>
            </div>
          </template>
        </el-table-column>
        
        <el-table-column width="90">
          <template #default="scope">
            <div class="table-hero-stats">
              <div class="stat-number">{{ scope.row.helpedUsers }}</div>
              <div class="stat-label">帮助用户</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="more-link">
        <el-button text type="primary">查看更多英雄 <el-icon><ArrowRight /></el-icon></el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, computed } from 'vue';
import { ArrowRight } from '@element-plus/icons-vue';

export default {
  name: 'HeroList',
  components: {
    ArrowRight
  },
  setup() {
    const timeFilter = ref('month');
    
    // 模拟英雄榜数据
    const heroData = ref([
      {
        id: 1,
        name: '陈思源',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 42,
        helpedUsers: 38,
        honorTitle: '拾光使者',
        department: '信息学院'
      },
      {
        id: 2,
        name: '李明轩',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 36,
        helpedUsers: 32,
        honorTitle: '温暖传递官',
        department: '机械工程学院'
      },
      {
        id: 3,
        name: '张小雨',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 31,
        helpedUsers: 29,
        honorTitle: '爱心守护者',
        department: '外国语学院'
      },
      {
        id: 4,
        name: '王浩然',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 28,
        helpedUsers: 25,
        honorTitle: '诚信先锋',
        department: '经济管理学院'
      },
      {
        id: 5,
        name: '林芳华',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 26,
        helpedUsers: 24,
        honorTitle: '微光传递者',
        department: '艺术学院'
      },
      {
        id: 6,
        name: '赵子豪',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 23,
        helpedUsers: 21,
        honorTitle: '校园好人',
        department: '体育学院'
      },
      {
        id: 7,
        name: '刘雨欣',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 21,
        helpedUsers: 19,
        honorTitle: '爱心使者',
        department: '医学院'
      }
    ]);
    
    // 计算前三名英雄
    const topThreeHeroes = computed(() => {
      return heroData.value.slice(0, 3);
    });
    
    // 计算剩余英雄
    const otherHeroes = computed(() => {
      return heroData.value.slice(3);
    });
    
    return {
      timeFilter,
      heroData,
      topThreeHeroes,
      otherHeroes
    };
  }
};
</script>

<style scoped>
.hero-list {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 30px;
}

.hero-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #f0f0f0;
}

.hero-header h3 {
  margin: 0;
  font-size: 20px;
  color: #303133;
  position: relative;
  padding-left: 15px;
}

.hero-header h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 20px;
  background: linear-gradient(to bottom, #409eff, #67c23a);
  border-radius: 2px;
}

.top-heroes {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 30px;
  padding: 15px 0;
}

.top-hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  border-radius: 10px;
  position: relative;
  width: 160px;
  transition: transform 0.3s;
}

.top-hero-card:hover {
  transform: translateY(-5px);
}

.top-hero-card.rank-1 {
  background: linear-gradient(135deg, #fff6e6, #ffd6a5);
  box-shadow: 0 4px 15px rgba(255, 164, 0, 0.2);
  height: 220px;
}

.top-hero-card.rank-2 {
  background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
  box-shadow: 0 4px 15px rgba(160, 160, 160, 0.2);
  height: 200px;
}

.top-hero-card.rank-3 {
  background: linear-gradient(135deg, #fff0e6, #ffcdb2);
  box-shadow: 0 4px 15px rgba(205, 127, 50, 0.2);
  height: 200px;
}

.rank-badge {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #f56c6c;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.top-hero-card.rank-1 .rank-badge {
  background-color: #ff9900;
  width: 36px;
  height: 36px;
  font-size: 18px;
}

.top-hero-card.rank-2 .rank-badge {
  background-color: #909399;
}

.top-hero-card.rank-3 .rank-badge {
  background-color: #e6a23c;
}

.hero-name {
  margin: 10px 0;
  font-weight: bold;
  color: #303133;
  font-size: 16px;
}

.hero-stats {
  display: flex;
  gap: 15px;
  margin-top: 5px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 20px;
  font-weight: bold;
  color: #303133;
}

.stat-label {
  font-size: 12px;
  color: #909399;
}

.honor-tag {
  position: absolute;
  bottom: 10px;
  padding: 2px 8px;
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  font-size: 12px;
  color: #67c23a;
}

.hero-table {
  margin-bottom: 15px;
}

.rank-number {
  width: 24px;
  height: 24px;
  background-color: #f2f6fc;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #606266;
}

.table-hero-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.table-hero-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-number {
  font-weight: bold;
  color: #303133;
}

.more-link {
  text-align: center;
  margin-top: 15px;
}

@media (max-width: 768px) {
  .top-heroes {
    flex-direction: column;
    align-items: center;
  }
  
  .top-hero-card {
    width: 80%;
    max-width: 250px;
    margin-bottom: 15px;
  }
}
</style> 